function getData(id){

var temp = document.getElementById(id).getAttribute("class");

if(temp=="b"||temp=="v"||temp=="m"){
if(document.getElementById("locked").innerHTML == "no"){ document.getElementById("menu").innerHTML = ''; }
}
else{
if(document.getElementById("locked").innerHTML == 'no'){

document.getElementById("menu").style.top = y+10;
document.getElementById("menu").style.left = x+10;


if(document.getElementById(id).innerHTML.search("transparent")!=-1){

buildScreen(id);

}

else{

buildingScreen(id);

}
}
}

}

function buildScreen(id){

var formated;
var builton;
var trans = 
[
[
"e",
"energy"
],
[
"o",
"asteriods"
],
[
"g",
"nebula"
],
[
"f",
"space"
]
];

for(var i = 0;i<trans.length;i++){

if(document.getElementById(id).getAttribute("class") == trans[i][0]){

builton = trans[i][1];

}

}

var optvar = "<select id='buildings'>";
var btemp = new Array();

for(var i = 0;i<buildings.length;i++){

if(buildings[i][1][0].search(builton)!=-1){

btemp[btemp.length] = buildings[i][0] + "|" + buildings[i][1][1];

}

}

btemp.sort();

for(var i = 0;i<btemp.length;i++){

var temp = btemp[i].split("|");
var ssrc = temp[1];
var ttitle = temp[0];

optvar = optvar + "<option value='"+ssrc+"'>"+ttitle+"</option>";

}

optvar = optvar + "</select>";

var tempId = id.replace("click_","")*1;
var coordY = Math.floor(tempId/mapWidth);
var coordX = tempId%mapWidth;

var writein = "<H2>Build!</H2>";
writein = writein + "Build a " + optvar + " at ["+coordX+","+coordY+"].<br>";
writein = writein + "Level/population: <input type='text' id='tlevel' maxlength='6' size='6' value='"+getDBL()+"'>";
writein = writein + "<BR><BR><input type='button' value='OK' onClick='placeBuilding(\""+id+"\")'>&nbsp;&nbsp;<input type='button' value='Cancel' onClick='locked(0);document.getElementById(\"menu\").innerHTML=\"\";'>";

document.getElementById("menu").innerHTML = writein;

}

function placeBuilding(id){

var building = document.getElementById("buildings").options[document.getElementById("buildings").selectedIndex].value;
var building2 = document.getElementById("buildings").options[document.getElementById("buildings").selectedIndex].innerHTML;
if(building2 == "Military Outpost" || building2 == "Alliance Command Station" || building2 == "Trade Outpost"){ document.getElementById("tlevel").value = 1; }
var IP = getIP();
document.getElementById(id).innerHTML = "<img src='"+IP+"foregrounds/"+building+"' height='32' width='32' title='"+building2+"'>";
document.getElementById(id).innerHTML = document.getElementById(id).innerHTML + "<span style='display:none;'>"+document.getElementById("tlevel").value+"</span>";
document.getElementById("menu").innerHTML = "";
locked(0);

}

function buildingScreen(id){

var level = document.getElementById(id).childNodes[1].innerHTML;

var buildingno = -1;

for(var i = 0;i<buildings.length;i++){

if(document.getElementById(id).childNodes[0].getAttribute("title") == buildings[i][0]){

buildingno = i;
break;

}

}

var comm = 0;
var bname = document.getElementById(id).childNodes[0].getAttribute("title");
var texttowrite = "<H2>"+bname+"</H2>";
if(bname == "Alliance Command Station"||bname == "Military Outpost"||bname == "Trade Outpost"){}
else{

texttowrite = texttowrite + "<p align='center'>";
if(bname.search("Planet")!=-1||bname.search("Starbase")!=-1){ texttowrite = texttowrite + "Population "; }
else{ texttowrite = texttowrite + "Level "; }
texttowrite = texttowrite + "<input type='text' id='level' onBlur='setLevel(\""+id+"\""; 
if(bname.search("Planet")!=-1||bname.search("Starbase")!=-1){ texttowrite = texttowrite + ",1"; }
texttowrite = texttowrite + ");' value='"+level+"' size='";
if(bname.search("Planet")!=-1||bname.search("Starbase")!=-1){ texttowrite = texttowrite + "6' maxlength = '6"; }
else{ texttowrite = texttowrite + "2' maxlength='2"; }
texttowrite = texttowrite + "'></p><br>";

}
texttowrite = texttowrite + "<table><tr><td valign='top'><table><tr><td colspan='2'>Consumption:</td></tr>";

for(var h = 0;h<buildings[buildingno][1][2][0].length;h++){

if(bname.search("Planet")!=-1||bname.search("Starbase")!=-1){ comm = Math.round((level/1000)*buildings[buildingno][1][2][0][h]); }
else{comm = Math.round(buildings[buildingno][1][2][0][h]*(1+0.4*(level-1))); }
texttowrite = texttowrite + "<tr><td>"+comm+"t</td><td>"+buildings[buildingno][1][2][1][h]+"</td></tr>";

}

texttowrite = texttowrite + "</table></td><td valign='top'><table><tr><td colspan='2'>Production:</td></tr>";

for(var h = 0;h<buildings[buildingno][1][3][0].length;h++){

if(bname.search("Planet")!=-1||bname.search("Starbase")!=-1){ comm = Math.round((level/1000)*buildings[buildingno][1][3][0][h]); }
else{ comm = Math.round(buildings[buildingno][1][3][0][h]*(1+0.5*(level-1))); }
texttowrite = texttowrite + "<tr><td>"+comm+"t</td><td>"+buildings[buildingno][1][3][1][h]+"</td></tr>";

}

texttowrite = texttowrite + "</table></td></tr></table><br><input type='button' value='OK' onClick='locked(0);document.getElementById(\"menu\").innerHTML=\"\";'>&nbsp;&nbsp;<input type='button' value='Delete Building' onClick='deleteBuilding(\""+id+"\")'>";

document.getElementById("menu").innerHTML = texttowrite;

}

function setLevel(id){

var level = document.getElementById("level").value;

if(isNaN(level)){ alert("Number please!"); }
else{ if(level <1){ alert("Now look here sonny, you cant have a building with a level < 1. (it just doesn't work that way!)"); document.getElementById("level").value=1; }
else{

document.getElementById(id).childNodes[1].innerHTML = level;
buildingScreen(id);

}
}
}

function deleteBuilding(id){

document.getElementById(id).innerHTML = "<img src='transparent.png'>";
document.getElementById("menu").innerHTML = '';
locked(0);

}